/*
                  FoodInfo Class Implementation
*/
#include "FoodInfo.h"

vector<FoodType*> FoodInfo::Types = vector<FoodType*>();

void FoodInfo::LoadFoodData(const string& strFilepath)
{
    FreeTypes();

    ifstream foodFile;

    foodFile.open(strFilepath.c_str());

    if (! foodFile.is_open())
    {
        cout<< "Couldn't read foodlist\n";

        foodFile.close();

        return;
    }

    string strLine = "";

    while (! foodFile.eof())
    {
        getline(foodFile, strLine);

        vector<string> Info = SplitString(strLine, ",");

        if (Info.size() == 3)
        {
            Types.push_back(new FoodType(Info.at(0), lexical_cast<int>(Info.at(1)), lexical_cast<int>(Info.at(1))));
        }
    }

    foodFile.close();
}

SDL_Surface* FoodInfo::getTypeSprite(const int& iType)
{
    if (iType < 0 || iType >= Types.size())
    {
        return NULL;
    }

    return Types.at(iType)->Sprite;
}

int FoodInfo::getNumTypes()
{
    return Types.size();
}

void FoodInfo::FreeTypes()
{
    for (int i = 0; i < Types.size(); i++)
    {
        delete Types.at(i);
    }

    Types.clear();
}

int FoodInfo::getTypeScore(const int& iType)
{
    if (iType < 0 || iType >= Types.size())
    {
        return 0;
    }

    return Types.at(iType)->iValue;
}
